﻿using CallCenter.Data.Base;
using CallCenter.Data.Helper;
using CallCenter.Data.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CallCenter.Data.BizUtilities
{
    public class RoleUserUtility : BaseUtility
    {
        public RoleUserUtility(DataManager manager)
            : base(manager)
        { }
        private static string _conn;
        DB dbConn;
        //Gets Roles
        public List<RoleUserModel> GetRoles()
        {
            using (var cmd = this.Factory.GetCommand("usp_RoleUserCrud", true, false)
                .AddParameter("@pMode", 1))
            {
                var param = this.Factory.AddParameter(cmd, "@pResult", System.Data.SqlDbType.NVarChar, 500, null);
                param.Direction = System.Data.ParameterDirection.Output;
                return this.Factory.ExecuteObjects<RoleUserModel>(cmd);
            }
        }

        public bool InsertRoleUser(RoleUserModel model)
        {
            using (var cmd = this.Factory.GetCommand("usp_RoleUserCrud", true, false))
            {
                cmd.AddParameter("@pMode", 0)
                .AddParameter("@pRoleId", model.RoleId)
                .AddParameter("@pUserId", model.UserId);

                var param = this.Factory.AddParameter(cmd, "@pResult", System.Data.SqlDbType.NVarChar, 500, null);
                param.Direction = System.Data.ParameterDirection.Output;

                cmd.ExecuteNonQuery();
                return true;
            }
        }

        public bool UpdateRoleUser(RoleUserModel model)
        {
            _conn = ConfigurationManager.ConnectionStrings["mainConnection"].ToString();
            dbConn = new DB(_conn);
            Hashtable ht = new Hashtable();
            ht.Add("RoleID", model.RoleId);
            ht.Add("UserID", model.UserId);
            dbConn.GetDataSetForSP("Sp_Update_tbl_Role_User", ht);
            return true;
        }

    }
}
